package com.mm.user.controller;



import com.mm.common.annotation.Log;
import com.mm.common.domain.po.Result;
import com.mm.user.domain.dto.LoginFormDTO;
import com.mm.common.domain.dto.UserDTO;
import com.mm.user.domain.po.User;
import com.mm.user.service.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @BelongsProject: 0.forum_system
 * @BelongsPackage: com.example.forum_system.controller
 * @Author : 游在海里的鱼
 * @CreateTime : 2023-11-07  14:23
 * @Version : 1.0
 * @Description : TODO
 */

@Slf4j
@Api(tags = "用户相关接口")
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserServiceImpl userServiceImpl;

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 注册
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="用户注册")
    @ApiOperation("用户注册")
    @PostMapping("/signUp")
    public Result signUp(LoginFormDTO loginFormDTO){
        return signUp(loginFormDTO);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 登录
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="用户登录")
    @ApiOperation("用户登录")
    @PostMapping("/signIn")
    public Result signIn(LoginFormDTO loginFormDTO){
        return userServiceImpl.login(loginFormDTO);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 登出
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="用户登出")
    @ApiOperation("用户登出")
    @GetMapping("/logout")
    public Result logout(){
        return userServiceImpl.logout();
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 获取用户信息
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="用户信息")
    @ApiOperation("用户信息")
    @GetMapping("/info")
    public Result<UserDTO> userInfo(Long id){
        return userServiceImpl.userInfo(id);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 修改用户信息
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="修改用户信息")
    @ApiOperation("修改用户信息")
    @PostMapping("/modifyInfo")
    public Result modifyInfo(UserDTO userDTO){
        return userServiceImpl.modifyInfo(userDTO);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 修改密码
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="修改密码")
    @ApiOperation("修改密码")
    @PostMapping("/modifyPwd")
    public Result modeifyPassword(String oldPassword,String newPassword){
        return userServiceImpl.modeifyPassword(oldPassword,newPassword);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 修改头像
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="修改头像")
    @ApiOperation("修改头像")
    @PostMapping("/sendAvatar")
    public Result sendImage(@RequestParam("image") MultipartFile image){
        return userServiceImpl.sendImage(image);
    }


}
